package com.example.infowall02.mapper;

import com.example.infowall02.domain.User;
import org.apache.ibatis.annotations.*;

@Mapper
public interface UserMapper {
    //增
    @Insert("INSERT INTO user (username, password, nickname, user_image) VALUES (#{username}, #{password}, null, null)")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    int saveUser(User user);
    //删
    @Delete("DELETE FROM user WHERE id = #{id}")
    public User deleteUserById(int id);
    //查
    @Select("SELECT id,username,password,nickname,user_image as userImage FROM user WHERE id = #{id}")
    public User getUserById(int id);
    @Select("SELECT id,username,password,nickname,user_image as userImage FROM user WHERE username = #{username} and password = #{password}")
    public User getUserByUsernameAndPassword(String username, String password);
    @Select("SELECT EXISTS (SELECT 1 FROM user WHERE username = #{username})")
    boolean existsByUsername(String username);
    @Select("SELECT id FROM user WHERE username = #{username}")
    public User getUserByUsername(String username);
    //测试是否有对应id的用户
    @Select("SELECT COUNT(*) FROM user WHERE id = #{id}")
    int countUserById(int userId);
    //改
    @Update("UPDATE user SET nickname = #{nickname} WHERE id = #{id}")//修改昵称
    public int updateUserNickname(String nickname,int id);
    @Update("UPDATE user SET user_image = #{userImage} WHERE id = #{id}")//修改头像
    public int updateUserImage(String userImage,int id);
    @Update("UPDATE user SET password = #{password} WHERE id = #{id}")//修改密码
    public int  updatePassword(String password,int id);
}
